﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwObracunKamataProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwObracunKamataProviderBaseCore : EntityViewProviderBase<VwObracunKamata>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwObracunKamata&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwObracunKamata&gt;"/></returns>
		protected static VList&lt;VwObracunKamata&gt; Fill(DataSet dataSet, VList<VwObracunKamata> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwObracunKamata>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwObracunKamata&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwObracunKamata>"/></returns>
		protected static VList&lt;VwObracunKamata&gt; Fill(DataTable dataTable, VList<VwObracunKamata> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwObracunKamata c = new VwObracunKamata();
					c.IDKnjizStavke = (Convert.IsDBNull(row["IDKnjizStavke"]))?(int)0:(System.Int32)row["IDKnjizStavke"];
					c.Konto = (Convert.IsDBNull(row["Konto"]))?string.Empty:(System.String)row["Konto"];
					c.MTSifra = (Convert.IsDBNull(row["MTSifra"]))?string.Empty:(System.String)row["MTSifra"];
					c.MT = (Convert.IsDBNull(row["MT"]))?(int)0:(System.Int32)row["MT"];
					c.IDKlijent = (Convert.IsDBNull(row["IDKlijent"]))?(int)0:(System.Int32?)row["IDKlijent"];
					c.MB = (Convert.IsDBNull(row["MB"]))?string.Empty:(System.String)row["MB"];
					c.ImeKlijenta = (Convert.IsDBNull(row["ImeKlijenta"]))?string.Empty:(System.String)row["ImeKlijenta"];
					c.LokacijeKlijenta = (Convert.IsDBNull(row["LokacijeKlijenta"]))?string.Empty:(System.String)row["LokacijeKlijenta"];
					c.Adresa = (Convert.IsDBNull(row["Adresa"]))?string.Empty:(System.String)row["Adresa"];
					c.Faktura = (Convert.IsDBNull(row["Faktura"]))?string.Empty:(System.String)row["Faktura"];
					c.DatumFakture = (Convert.IsDBNull(row["DatumFakture"]))?DateTime.MinValue:(System.DateTime)row["DatumFakture"];
					c.Iznos = (Convert.IsDBNull(row["Iznos"]))?0:(System.Decimal?)row["Iznos"];
					c.RazdobljeOd = (Convert.IsDBNull(row["RazdobljeOd"]))?DateTime.MinValue:(System.DateTime?)row["RazdobljeOd"];
					c.RazdobljeDo = (Convert.IsDBNull(row["RazdobljeDo"]))?DateTime.MinValue:(System.DateTime?)row["RazdobljeDo"];
					c.Dana = (Convert.IsDBNull(row["Dana"]))?(int)0:(System.Int32?)row["Dana"];
					c.Stopa = (Convert.IsDBNull(row["Stopa"]))?0.0f:(System.Double)row["Stopa"];
					c.IznosKamate = (Convert.IsDBNull(row["IznosKamate"]))?0:(System.Decimal?)row["IznosKamate"];
					c.DatumZadnjeUplate = (Convert.IsDBNull(row["DatumZadnjeUplate"]))?DateTime.MinValue:(System.DateTime?)row["DatumZadnjeUplate"];
					c.DatumOd = (Convert.IsDBNull(row["DatumOd"]))?DateTime.MinValue:(System.DateTime)row["DatumOd"];
					c.DatumDo = (Convert.IsDBNull(row["DatumDo"]))?DateTime.MinValue:(System.DateTime)row["DatumDo"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwObracunKamata&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwObracunKamata&gt;"/></returns>
		protected VList<VwObracunKamata> Fill(IDataReader reader, VList<VwObracunKamata> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwObracunKamata entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwObracunKamata>("VwObracunKamata",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwObracunKamata();
					}
					entity.IDKnjizStavke = (System.Int32)reader["IDKnjizStavke"];
					//entity.IDKnjizStavke = (Convert.IsDBNull(reader["IDKnjizStavke"]))?(int)0:(System.Int32)reader["IDKnjizStavke"];
					entity.Konto = (System.String)reader["Konto"];
					//entity.Konto = (Convert.IsDBNull(reader["Konto"]))?string.Empty:(System.String)reader["Konto"];
					entity.MTSifra = (System.String)reader["MTSifra"];
					//entity.MTSifra = (Convert.IsDBNull(reader["MTSifra"]))?string.Empty:(System.String)reader["MTSifra"];
					entity.MT = (System.Int32)reader["MT"];
					//entity.MT = (Convert.IsDBNull(reader["MT"]))?(int)0:(System.Int32)reader["MT"];
					entity.IDKlijent = reader.IsDBNull(reader.GetOrdinal("IDKlijent")) ? null : (System.Int32?)reader["IDKlijent"];
					//entity.IDKlijent = (Convert.IsDBNull(reader["IDKlijent"]))?(int)0:(System.Int32?)reader["IDKlijent"];
					entity.MB = reader.IsDBNull(reader.GetOrdinal("MB")) ? null : (System.String)reader["MB"];
					//entity.MB = (Convert.IsDBNull(reader["MB"]))?string.Empty:(System.String)reader["MB"];
					entity.ImeKlijenta = (System.String)reader["ImeKlijenta"];
					//entity.ImeKlijenta = (Convert.IsDBNull(reader["ImeKlijenta"]))?string.Empty:(System.String)reader["ImeKlijenta"];
					entity.LokacijeKlijenta = reader.IsDBNull(reader.GetOrdinal("LokacijeKlijenta")) ? null : (System.String)reader["LokacijeKlijenta"];
					//entity.LokacijeKlijenta = (Convert.IsDBNull(reader["LokacijeKlijenta"]))?string.Empty:(System.String)reader["LokacijeKlijenta"];
					entity.Adresa = reader.IsDBNull(reader.GetOrdinal("Adresa")) ? null : (System.String)reader["Adresa"];
					//entity.Adresa = (Convert.IsDBNull(reader["Adresa"]))?string.Empty:(System.String)reader["Adresa"];
					entity.Faktura = reader.IsDBNull(reader.GetOrdinal("Faktura")) ? null : (System.String)reader["Faktura"];
					//entity.Faktura = (Convert.IsDBNull(reader["Faktura"]))?string.Empty:(System.String)reader["Faktura"];
					entity.DatumFakture = (System.DateTime)reader["DatumFakture"];
					//entity.DatumFakture = (Convert.IsDBNull(reader["DatumFakture"]))?DateTime.MinValue:(System.DateTime)reader["DatumFakture"];
					entity.Iznos = reader.IsDBNull(reader.GetOrdinal("Iznos")) ? null : (System.Decimal?)reader["Iznos"];
					//entity.Iznos = (Convert.IsDBNull(reader["Iznos"]))?0:(System.Decimal?)reader["Iznos"];
					entity.RazdobljeOd = reader.IsDBNull(reader.GetOrdinal("RazdobljeOd")) ? null : (System.DateTime?)reader["RazdobljeOd"];
					//entity.RazdobljeOd = (Convert.IsDBNull(reader["RazdobljeOd"]))?DateTime.MinValue:(System.DateTime?)reader["RazdobljeOd"];
					entity.RazdobljeDo = reader.IsDBNull(reader.GetOrdinal("RazdobljeDo")) ? null : (System.DateTime?)reader["RazdobljeDo"];
					//entity.RazdobljeDo = (Convert.IsDBNull(reader["RazdobljeDo"]))?DateTime.MinValue:(System.DateTime?)reader["RazdobljeDo"];
					entity.Dana = reader.IsDBNull(reader.GetOrdinal("Dana")) ? null : (System.Int32?)reader["Dana"];
					//entity.Dana = (Convert.IsDBNull(reader["Dana"]))?(int)0:(System.Int32?)reader["Dana"];
					entity.Stopa = (System.Double)reader["Stopa"];
					//entity.Stopa = (Convert.IsDBNull(reader["Stopa"]))?0.0f:(System.Double)reader["Stopa"];
					entity.IznosKamate = reader.IsDBNull(reader.GetOrdinal("IznosKamate")) ? null : (System.Decimal?)reader["IznosKamate"];
					//entity.IznosKamate = (Convert.IsDBNull(reader["IznosKamate"]))?0:(System.Decimal?)reader["IznosKamate"];
					entity.DatumZadnjeUplate = reader.IsDBNull(reader.GetOrdinal("DatumZadnjeUplate")) ? null : (System.DateTime?)reader["DatumZadnjeUplate"];
					//entity.DatumZadnjeUplate = (Convert.IsDBNull(reader["DatumZadnjeUplate"]))?DateTime.MinValue:(System.DateTime?)reader["DatumZadnjeUplate"];
					entity.DatumOd = (System.DateTime)reader["DatumOd"];
					//entity.DatumOd = (Convert.IsDBNull(reader["DatumOd"]))?DateTime.MinValue:(System.DateTime)reader["DatumOd"];
					entity.DatumDo = (System.DateTime)reader["DatumDo"];
					//entity.DatumDo = (Convert.IsDBNull(reader["DatumDo"]))?DateTime.MinValue:(System.DateTime)reader["DatumDo"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwObracunKamata"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunKamata"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwObracunKamata entity)
		{
			reader.Read();
			entity.IDKnjizStavke = (System.Int32)reader["IDKnjizStavke"];
			//entity.IDKnjizStavke = (Convert.IsDBNull(reader["IDKnjizStavke"]))?(int)0:(System.Int32)reader["IDKnjizStavke"];
			entity.Konto = (System.String)reader["Konto"];
			//entity.Konto = (Convert.IsDBNull(reader["Konto"]))?string.Empty:(System.String)reader["Konto"];
			entity.MTSifra = (System.String)reader["MTSifra"];
			//entity.MTSifra = (Convert.IsDBNull(reader["MTSifra"]))?string.Empty:(System.String)reader["MTSifra"];
			entity.MT = (System.Int32)reader["MT"];
			//entity.MT = (Convert.IsDBNull(reader["MT"]))?(int)0:(System.Int32)reader["MT"];
			entity.IDKlijent = reader.IsDBNull(reader.GetOrdinal("IDKlijent")) ? null : (System.Int32?)reader["IDKlijent"];
			//entity.IDKlijent = (Convert.IsDBNull(reader["IDKlijent"]))?(int)0:(System.Int32?)reader["IDKlijent"];
			entity.MB = reader.IsDBNull(reader.GetOrdinal("MB")) ? null : (System.String)reader["MB"];
			//entity.MB = (Convert.IsDBNull(reader["MB"]))?string.Empty:(System.String)reader["MB"];
			entity.ImeKlijenta = (System.String)reader["ImeKlijenta"];
			//entity.ImeKlijenta = (Convert.IsDBNull(reader["ImeKlijenta"]))?string.Empty:(System.String)reader["ImeKlijenta"];
			entity.LokacijeKlijenta = reader.IsDBNull(reader.GetOrdinal("LokacijeKlijenta")) ? null : (System.String)reader["LokacijeKlijenta"];
			//entity.LokacijeKlijenta = (Convert.IsDBNull(reader["LokacijeKlijenta"]))?string.Empty:(System.String)reader["LokacijeKlijenta"];
			entity.Adresa = reader.IsDBNull(reader.GetOrdinal("Adresa")) ? null : (System.String)reader["Adresa"];
			//entity.Adresa = (Convert.IsDBNull(reader["Adresa"]))?string.Empty:(System.String)reader["Adresa"];
			entity.Faktura = reader.IsDBNull(reader.GetOrdinal("Faktura")) ? null : (System.String)reader["Faktura"];
			//entity.Faktura = (Convert.IsDBNull(reader["Faktura"]))?string.Empty:(System.String)reader["Faktura"];
			entity.DatumFakture = (System.DateTime)reader["DatumFakture"];
			//entity.DatumFakture = (Convert.IsDBNull(reader["DatumFakture"]))?DateTime.MinValue:(System.DateTime)reader["DatumFakture"];
			entity.Iznos = reader.IsDBNull(reader.GetOrdinal("Iznos")) ? null : (System.Decimal?)reader["Iznos"];
			//entity.Iznos = (Convert.IsDBNull(reader["Iznos"]))?0:(System.Decimal?)reader["Iznos"];
			entity.RazdobljeOd = reader.IsDBNull(reader.GetOrdinal("RazdobljeOd")) ? null : (System.DateTime?)reader["RazdobljeOd"];
			//entity.RazdobljeOd = (Convert.IsDBNull(reader["RazdobljeOd"]))?DateTime.MinValue:(System.DateTime?)reader["RazdobljeOd"];
			entity.RazdobljeDo = reader.IsDBNull(reader.GetOrdinal("RazdobljeDo")) ? null : (System.DateTime?)reader["RazdobljeDo"];
			//entity.RazdobljeDo = (Convert.IsDBNull(reader["RazdobljeDo"]))?DateTime.MinValue:(System.DateTime?)reader["RazdobljeDo"];
			entity.Dana = reader.IsDBNull(reader.GetOrdinal("Dana")) ? null : (System.Int32?)reader["Dana"];
			//entity.Dana = (Convert.IsDBNull(reader["Dana"]))?(int)0:(System.Int32?)reader["Dana"];
			entity.Stopa = (System.Double)reader["Stopa"];
			//entity.Stopa = (Convert.IsDBNull(reader["Stopa"]))?0.0f:(System.Double)reader["Stopa"];
			entity.IznosKamate = reader.IsDBNull(reader.GetOrdinal("IznosKamate")) ? null : (System.Decimal?)reader["IznosKamate"];
			//entity.IznosKamate = (Convert.IsDBNull(reader["IznosKamate"]))?0:(System.Decimal?)reader["IznosKamate"];
			entity.DatumZadnjeUplate = reader.IsDBNull(reader.GetOrdinal("DatumZadnjeUplate")) ? null : (System.DateTime?)reader["DatumZadnjeUplate"];
			//entity.DatumZadnjeUplate = (Convert.IsDBNull(reader["DatumZadnjeUplate"]))?DateTime.MinValue:(System.DateTime?)reader["DatumZadnjeUplate"];
			entity.DatumOd = (System.DateTime)reader["DatumOd"];
			//entity.DatumOd = (Convert.IsDBNull(reader["DatumOd"]))?DateTime.MinValue:(System.DateTime)reader["DatumOd"];
			entity.DatumDo = (System.DateTime)reader["DatumDo"];
			//entity.DatumDo = (Convert.IsDBNull(reader["DatumDo"]))?DateTime.MinValue:(System.DateTime)reader["DatumDo"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwObracunKamata"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunKamata"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwObracunKamata entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDKnjizStavke = (Convert.IsDBNull(dataRow["IDKnjizStavke"]))?(int)0:(System.Int32)dataRow["IDKnjizStavke"];
			entity.Konto = (Convert.IsDBNull(dataRow["Konto"]))?string.Empty:(System.String)dataRow["Konto"];
			entity.MTSifra = (Convert.IsDBNull(dataRow["MTSifra"]))?string.Empty:(System.String)dataRow["MTSifra"];
			entity.MT = (Convert.IsDBNull(dataRow["MT"]))?(int)0:(System.Int32)dataRow["MT"];
			entity.IDKlijent = (Convert.IsDBNull(dataRow["IDKlijent"]))?(int)0:(System.Int32?)dataRow["IDKlijent"];
			entity.MB = (Convert.IsDBNull(dataRow["MB"]))?string.Empty:(System.String)dataRow["MB"];
			entity.ImeKlijenta = (Convert.IsDBNull(dataRow["ImeKlijenta"]))?string.Empty:(System.String)dataRow["ImeKlijenta"];
			entity.LokacijeKlijenta = (Convert.IsDBNull(dataRow["LokacijeKlijenta"]))?string.Empty:(System.String)dataRow["LokacijeKlijenta"];
			entity.Adresa = (Convert.IsDBNull(dataRow["Adresa"]))?string.Empty:(System.String)dataRow["Adresa"];
			entity.Faktura = (Convert.IsDBNull(dataRow["Faktura"]))?string.Empty:(System.String)dataRow["Faktura"];
			entity.DatumFakture = (Convert.IsDBNull(dataRow["DatumFakture"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumFakture"];
			entity.Iznos = (Convert.IsDBNull(dataRow["Iznos"]))?0:(System.Decimal?)dataRow["Iznos"];
			entity.RazdobljeOd = (Convert.IsDBNull(dataRow["RazdobljeOd"]))?DateTime.MinValue:(System.DateTime?)dataRow["RazdobljeOd"];
			entity.RazdobljeDo = (Convert.IsDBNull(dataRow["RazdobljeDo"]))?DateTime.MinValue:(System.DateTime?)dataRow["RazdobljeDo"];
			entity.Dana = (Convert.IsDBNull(dataRow["Dana"]))?(int)0:(System.Int32?)dataRow["Dana"];
			entity.Stopa = (Convert.IsDBNull(dataRow["Stopa"]))?0.0f:(System.Double)dataRow["Stopa"];
			entity.IznosKamate = (Convert.IsDBNull(dataRow["IznosKamate"]))?0:(System.Decimal?)dataRow["IznosKamate"];
			entity.DatumZadnjeUplate = (Convert.IsDBNull(dataRow["DatumZadnjeUplate"]))?DateTime.MinValue:(System.DateTime?)dataRow["DatumZadnjeUplate"];
			entity.DatumOd = (Convert.IsDBNull(dataRow["DatumOd"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumOd"];
			entity.DatumDo = (Convert.IsDBNull(dataRow["DatumDo"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumDo"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwObracunKamataFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunKamata"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunKamataFilterBuilder : SqlFilterBuilder<VwObracunKamataColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunKamataFilterBuilder class.
		/// </summary>
		public VwObracunKamataFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunKamataFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunKamataFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunKamataFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunKamataFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunKamataFilterBuilder

	#region VwObracunKamataParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunKamata"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunKamataParameterBuilder : ParameterizedSqlFilterBuilder<VwObracunKamataColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunKamataParameterBuilder class.
		/// </summary>
		public VwObracunKamataParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunKamataParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunKamataParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunKamataParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunKamataParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunKamataParameterBuilder
} // end namespace
